#ifndef PROJECTTREEMODEL_H
#define PROJECTTREEMODEL_H

#include <QMutex>
#include <QAbstractItemModel>
#include <QStringList>
class QFileSystemWatcher;
class Node;
class QSettings;
class IconProvider;
class QFileInfo;

namespace Plugins
{
    class Project;
}

class ProjectTreeModel : public QAbstractItemModel
{
    Q_OBJECT
public:
    explicit ProjectTreeModel(const QString & path, Plugins::Project *set, QObject *parent = 0);
    ~ProjectTreeModel();

    QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
    QModelIndex parent(const QModelIndex & index) const;
    int rowCount(const QModelIndex & parent = QModelIndex()) const;
    int columnCount(const QModelIndex & parent = QModelIndex()) const;
    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole);
    void setIconProvider(IconProvider*);
    QList<QModelIndex> indexForPath(const QString & path);
    void setModify(const QString & path, bool m);
public slots:
    void onDirectoryChanged(const QString &, bool rec = false);
private slots:
    void onFileChanged(const QString &);
    void onNodeDestroy(QList<Node*> nodes);
private:
    void readTree(const QString & parentPath = "", bool rec = true);
    Node *specNode(const QString & path, const QString & type);
    QList<QModelIndex> find(QModelIndex startIndex, Node * node);
    Node * createNode(const QFileInfo & info, const QString & spec = "");
    Node * createNode(const QString & info, const QString & spec = "");
private:
    QFileSystemWatcher *_watcher;
    QString _rootPath;
    Node * _root;
    Plugins::Project *_project;
    IconProvider *_provider;
    QMutex _mutex;
};

#endif // PROJECTTREEMODEL_H
